<template>
    <div>
        <h3>房价计划添加</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房价计划名称</td>
                    <td><input type="text" v-model="a.HousePriceName"></td>
                </tr>
                <tr>
                    <td>门店</td>
                    <td><select v-model="a.ShopId">
                            <option value="">请选择</option>
                            <option :value="item.Id" v-for="item in data.shopList">{{ item.ShopName }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>房型名称</td>
                    <td><select v-model="a.HouseTypeId">
                            <option value="">请选择</option>
                            <option :value="item.Id" v-for="item in data.housetypeList">{{ item.HouseTypeName }}</option>
                        </select>
                    </td>
                </tr>
                
                <tr>
                    <td>房型价格</td>
                    <td><input type="text" v-model="a.Price"></td>
                </tr>
                <tr>
                    <td>房间数量</td>
                    <td><input type="text" v-model="a.Count"></td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td><input type="radio" name="state" v-model="a.State" :value="1" />开启
                        <input type="radio" name="state" v-model="a.State" :value="0" />禁用
                    </td>
                </tr>
                <tr>
                    <td>早餐数量</td>
                    <td><input type="text" v-model="a.BreakfastCount"></td>
                </tr>
                <tr>
                    <td>开始时间</td>
                    <td><input type="date" v-model="a.BeginTime"></td>
                </tr>
                <tr>
                    <td>结束时间</td>
                    <td><input type="date" v-model="a.EndTime"></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="增加" @click="ok"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import axios from 'axios';
import moment from 'moment';
const router = useRouter();
const route = useRoute();

onMounted(() => {
    getshoplist();
    gettypelist();
})

let a: any = reactive({
    HousePriceName: '',
    ShopId: '',
    HouseTypeId: '',
    Price: '',
    Count: '',
    State: '',
    BreakfastCount: '',
    BeginTime: '',
    EndTime: ''
})

let data: any = reactive({
    shopList: [],
    housetypeList: []
})

const getshoplist = () => {
    axios({
        method: 'get',
        url: '/api/Shop/GetShopList',
        params: {
            pageSize: 99,
            pageIndex: 1
        }
    })
        .then((res) => {
            console.log(res)
            data.shopList = res.data.list;


        })
        .catch((err) => {
            console.log(err);
        })
}

const gettypelist = () => {
    axios({
        url: 'api/HouseType/ShowHouse',
        method: 'get',
        params: {
            pageYe: 1,
            pageHang: 99
        }
    })
        .then((res) => {
            console.log(res);
            data.housetypeList = res.data.list;
        })
}
const ok: any = () => {
    axios({
        url: '/api/HousePricePlan/HousePriceAdd',
        method: 'post',
        data: a
    })
        .then((res) => {
            if (res.data == -1) {
                alert("重复");
                return;
            }
            if (res.data > 0) {
                alert("成功");
                router.push("/housepricelist")
            }
        })
}



</script>

<style scoped></style>